/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dp1.pucp.Simulacion.DAO;
import com.dp1.pucp.Modelo.Clases.*;
import com.dp1.pucp.Util.HibernateUtil;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Aventura y la Señorita
 */
public class CargaMasivaDAO {
   
        public void guardarMaquina(ArrayList<Maquina> lstMaq){
            Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Maquina e:lstMaq){
                session.saveOrUpdate(e);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
      }
        
      public void guardarhistorico(ArrayList<Historico> lstHis){
        
          Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Historico e:lstHis){
                session.saveOrUpdate(e);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
        
        
     }
        
        public void guardarEmpleados(ArrayList<Empleado> lstEmp) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Empleado e:lstEmp){
                session.saveOrUpdate(e);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarHistorico(ArrayList<Historico> lstHis) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Historico h:lstHis){
                session.saveOrUpdate(h);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarMaquinas(ArrayList<Maquina> lstMaq) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Maquina m:lstMaq){
                session.saveOrUpdate(m);                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarProveedores(ArrayList<Proveedor> lstProv) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Proveedor p:lstProv){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarMateriaPrima(ArrayList<Materiaprima> lstMatPri) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Materiaprima m:lstMatPri){
                session.saveOrUpdate(m);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarReceta(ArrayList<RecetaPfMp> lstRecet) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (RecetaPfMp r:lstRecet){
                session.saveOrUpdate(r);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarRecetaPI(ArrayList<RecetaPfPi> lstRecet) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (RecetaPfPi r:lstRecet){
                session.saveOrUpdate(r);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarProductoXMaquina(ArrayList<Productoxmaquina> lstPxM) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Productoxmaquina pm:lstPxM){
                session.saveOrUpdate(pm);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    public void guardarProductoIntermedio(ArrayList<Productointermedio> lstPro) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Productointermedio p:lstPro){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarProductoFinales(ArrayList<Productofinal> lstPro) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Productofinal p:lstPro){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarCostosInsumos(ArrayList<Costoinsumos> lstCos) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Costoinsumos c:lstCos){
                session.saveOrUpdate(c);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarTipoProducto(ArrayList<Tipoproducto> lstTip) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Tipoproducto t:lstTip){
                session.saveOrUpdate(t);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
    
    public void guardarClientesMasiva(ArrayList<Cliente> lstCli) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Cliente c:lstCli){
                session.saveOrUpdate(c);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }
        
    public void guardarProductoFinal(ArrayList<Productofinal> lstPro) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Productofinal p:lstPro){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }    
        
      public void guardarClientes(ArrayList<Cliente> lstCli) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Cliente p:lstCli){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }   

      
      public void guardarPresentacion(ArrayList<Presentacion> lstCli) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Presentacion p:lstCli){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }   

      
      public void guardarPrecios( ArrayList<Precio> lstCli) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Precio p:lstCli){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }   

      
      public void guardarAlmacen(ArrayList<Almacen> lstCli) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Almacen p:lstCli){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }   

      
      public void guardarTipoCambio(ArrayList<Tipodecambio> lstCli) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        try {
            for (Tipodecambio p:lstCli){
                session.saveOrUpdate(p);
                
            }           
            tx.commit();
        } catch (HibernateException e) {
            throw new HibernateException(e);
        } finally {
            session.close();
        }
    }   

      
}
